<?php
/**
 * A simple description for this script
 *
 * PHP Version 5.2.0 or Upper version
 *
 * @package    Paylog
 * @author     Hidehito NOZAWA aka Suin <http://suin.asia>
 * @copyright  2010 Hidehito NOZAWA
 * @license    http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
 *
 */

class Paylog_Language_Manager
{
	public static function getCatalogue()
	{
		$encode   = strtolower(Paylog::$cms->charset);
		$langcode = strtolower(Paylog::$cms->langcode);

		$langFile  = PAYLOG_PATH.'/language/'.$langcode.'.xml';

		if ( !file_exists($langFile) )
		{
			return array();
		}

		$cacheDir = Paylog::$cms->cachePath;

		$cacheFile = $cacheDir.'/'.PAYLOG_DIR.'_'.$langcode.'_'.$encode.'.php';

		if ( file_exists($cacheFile) )
		{
			$catalogue = require $cacheFile;
//			return $catalogue;
		}

		$langXml = simplexml_load_file($langFile, 'Paylog_Language_Xml');
		$catalogue = $langXml->getCatalogue();

		if ( $encode != 'utf-8' )
		{
			mb_convert_variables($encode, 'UTF-8', $catalogue);
		}

		$cacheContent = "<?php\nreturn ".var_export($catalogue, true).";\n?>\n";

		file_put_contents($cacheFile, $cacheContent);

		return $catalogue;
	}
}

?>
